package com.application.meizhi.uitl;


import com.application.meizhi.model.douban.DouBanMeiZhi;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * Created by zeng on 2016/10/13.
 */

public class MeiZhiUtils {
    public static List<DouBanMeiZhi> parserDouBanListHtml(String type, Response<ResponseBody> response) {
        List<DouBanMeiZhi> lists = new ArrayList<>();


        try {
            String html = response.body().string();

            Document document = Jsoup.parse(html);
            Elements elements = document.select("div[class=thumbnail]>div[class=img_single]>a>img");
            for (Element e : elements) {

                DouBanMeiZhi douBanMeiZhi = new DouBanMeiZhi();

                douBanMeiZhi.setUrl(e.attr("src"));
                douBanMeiZhi.setTitle(e.attr("title"));
                douBanMeiZhi.setType(type);
                lists.add(douBanMeiZhi);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lists;
    }


}
